IEnumerable<object> GetResources(System.Reflection.Assembly inAssembly, System.Globalization.CultureInfo inCultureInfo) =>
((System.Resources.ResourceManager)inAssembly
.GetTypes()
.FirstOrDefault(type => type.Name == "Resources")
.GetProperty("ResourceManager", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)
.GetValue(null, null))
.GetResourceSet(inCultureInfo, true, true)
.OfType<System.Collections.DictionaryEntry>()
.Select(item => item.Value);
var resources = GetResources(System.Reflection.Assembly.GetCallingAssembly(), System.Globalization.CultureInfo.InvariantCulture);
public IEnumerable<string> GetPhotoUrl() =>
Api
.Wall
.Get(new WallGetParams
{
Domain = "lol.community",
Count = 2
})
.WallPosts
.Select(item => item.Attachments.FirstOfDefault()?.Instance)
.OfType<Photo>()
.Select(item => item.Sizes.FirstOfDefault()?.Url.AbsoluteUrl.ToString());
readonly static System.Text.Encoding WINDOWS1251 = Encoding.GetEncoding(1251);
readonly static System.Text.Encoding UTF8 = Encoding.UTF8;
static string ConvertWin1251ToUTF8(string inString)
{
return UTF8.GetString(WINDOWS1251.GetBytes(inString));
}
const string DOCUMENT_FORMAT_OPEN_XML = "DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppDomain.CurrentDomain.AssemblyResolve += (sender, e) =>
{
switch (e.Name)
{
case DOCUMENT_FORMAT_OPEN_XML: return Assembly.Load(Properties.Resources.DocumentFormat_OpenXml);
default: return null;
}
};
Application.Run(new MainFrom());
}
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Windows.Forms;
namespace serialport_process
{
class Program
{
class OutputForm : Form
{
public RichTextBox richTextBox {get ;private set;}
public OutputForm()
{
WindowState = FormWindowState.Maximized;
richTextBox = new RichTextBox
{
Dock = DockStyle.Fill
};
}
}
static Encoding ENCODING = Encoding.ASCII;
const int BUFFER_SIZE = 4096;
static byte[] buffer = new byte[BUFFER_SIZE];
delegate void AppendText(string inText);
static void Main(string[] args)
{
var form = new OutputForm();
var task = new Task(() =>
{
var serialPort = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.Two);
serialPort.DataReceived += (sender, e) =>
{
var count = serialPort.BytesToRead;
while (count > 0)
{
var current_count = serialPort.Read(buffer, 0, count < BUFFER_SIZE ? count : BUFFER_SIZE);
var text = ENCODING.GetString(buffer, 0, current_count);
count -= current_count;
form.Invoke((AppendText)(txt => form.richTextBox.AppendText(txt)), text);
}
};
serialPort.Open();
while (true) ;
});
form.Load += (sender, e) => task.Start();
Application.Run(form);
}
}
}
static IEnumerable<string> Compare<T>(T a, T b)
where T : class
{
return typeof(T)
.GetProperties()
.Where(pi => !pi.GetValue(a, null).Equals(pi.GetValue(b, null)))
.Select(pi=>pi.Name);
}
string _StateValue;
public string stateValue
{
get {return _StateValue; }
set
{
_StateValue = value;
OnStateValueChanged(value); //этот метод генерирует событие на которое подписаны все кому интересно изменения этого поля, например при изменении поля могут по событию перерисовываться форма
}
}
string _CaсhedValue = null;
string cachedValue
{
get
{
if (_CachedValue == null)
{
_CachedValue = CreateValue(); //этот метод вычисляет значение
}
return _CachedValue;
}
}
PointF _Start;
PointF _Stop;
PointF center
{
get
{
return new PointF((_Start.X+_Stop.X)/2,(_Start.Y+_Stop.Y)/2);
}
}