|
Got it working. Without generic mess.
Thougt I tryed everything.
public interface _IMedia { }
public interface _IAudio : _IMedia { }
public interface _IVideo : _IAudio { }
public class CMedia : _IVideo
{
}
public interface _IMediaPlayer
{
_IMedia Media { get; }
}
public interface _IAudioPlayer : _IMediaPlayer
{
new _IAudio Media { get; }
}
public interface _IVideoPlayer : _IAudioPlayer
{
new _IVideo Media { get; }
}
public class _CMediaPlayer : _IMediaPlayer
{
private CMedia m_Media = new CMedia();
public _IMedia Media { get { return m_Media; } }
}
public class _CAudioPlayer : _CMediaPlayer, _IAudioPlayer
{
public new _IAudio Media { get { return base.Media as _IAudio; } }
}
public class CVideoPlayer : _CAudioPlayer, _IVideoPlayer
{
public new _IVideo Media { get { return base.Media as _IVideo; } }
}
|
|
|
|
|
Hm, what about the Liskov principle (see e.g. http://en.wikipedia.org/wiki/Liskov_substitution_principle[^])? Your example somehow reminds me of the square-and-rectangle issue there...
In case that the VideoPlayer can use some code of the AudioPlayer, I'd go for composition instead of inheritance.
|
|
|
|
|
Thanks. It's a good idea, but in my case it was more about hiding properties that isnt 'needed'. Player & Media is allways initzialed as video type.
|
|
|
|
|
Hi,
You could do it with generics in the following way:
public interface IMedia
{
}
public interface IAudio : IMedia
{
}
public interface IVideo : IAudio
{
}
public interface IMediaPlayer<T> where T : IMedia
{
T Media
{
get;
}
}
public interface IAudioPlayer<T> : IMediaPlayer<T> where T : IAudio
{
}
public interface IVideoPlayer<T> : IAudioPlayer<T> where T : IVideo
{
}
public class Class1
{
public void Example()
{
IVideoPlayer<IVideo> videoPlayer = null;
IAudioPlayer<IAudio> audioPlayer = null;
}
}
The problem is that your video player can't be compiled against IVideo and use an audio player compiled against IAudio. Your video player and audio player need to be compiled against the same type.
I don't know what this issue with generics is called, but I always find that generics bread more generics.
Kind Regards,
Keld Ølykke
|
|
|
|
|
Hi !
I need help with converting 24 bit input to 16 bit "on the fly" im trying to record audio output, if the format is set to 24 bit depth i have problem with mix it down to one channel (sound is slower) here is the example wchich im using to convert if audio has 32 bit i dont know how to change this code if input has 24 bit
byte[] newArray16Bit = new byte[e.BytesRecorded / 2];
short two;
float value;
for (int i = 0, j = 0; i < e.BytesRecorded; i += 4, j += 2)
{
value = (BitConverter.ToSingle(e.Buffer, i));
two = (short)(value * short.MaxValue);
newArray16Bit[j] = (byte)(two & 0xFF);
newArray16Bit[j + 1] = (byte)((two >> 8) & 0xFF);
}
byte[] mono = StereoToMono(newArray16Bit);
OutFile.Write(mono);
i found sample code to convert but it returns float[] i need byte:
public float[] Convert24BitToFloat(byte[] input)
{
int inputSamples = input.Length / 3;
float[] output = new float[inputSamples];
int outputIndex = 0;
var temp = new byte[4];
for(int n = 0; n < inputSamples; n++)
{
Array.Copy(input,n*3,temp,0,3);
int sample = BitConverter.ToInt32(temp,0);
output[outputIndex++] = sample / 16777216f;
}
return output;
}
|
|
|
|
|
Instead of calculating with bytes, go to the samples. Samples are 16bit ints, 24bit ints (which are not well represented in .Net), or 32bit floats. Then do your calculations on the samples. And then convert to the output format.
|
|
|
|
|
I'm given a string which contains an arbitrary amount of code. I want to calculate a number which represents the code complexity of that string. Something like:
int complexity = Lib.FindComplexity(someString);
I realize there are a lot of tools out there that will do this for you. These tools will not work for me, because I want to do it programmatically. I'd love for the library to be in C#, but will work with anything at this point.
Thanks in advance!
|
|
|
|
|
gastonbed wrote: Thanks in advance!
For what? Are you asking how to build this, or stuck with anything else?
The "parts" that build up code-complexity are described here[^]. You'd be writing code to do the same.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Calculating cyclomatic complexity needs not to verify "every possible execution path".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Cyclomatic complexity is a heuristic that approximates the code's complexity. It doesn't always reflect the true complexity.
|
|
|
|
|
Alan Balkany wrote: It doesn't always reflect the true complexity. The true tao cannot be named indeed. Estimating total complexity of a method using numbers takes multiple factors. Even the LOC and amount of local variables gives an indication. Weight various indications, and you get a ranking that might not equal a subjective estimate of complexity.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have a menustrip like as
a
b
c
i wanna to add a new menuitem in this menu named as d from database
and now my menustrip is looks like
a
b
c
d
now m wanna to add another menuitem in this menu as e from database
but now my menu shows
a
b
c
d
a
b
c
d
e
but i wanna tht my menu shows as
a
b
c
d
e
can anyone help me in it
|
|
|
|
|
Show the code you are using; we cannot guess what is going wrong from the above.
Use the best guess
|
|
|
|
|
public void SubMenu(ToolStripMenuItem menuitem, string submenu)
{
string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')";
DataTable dt = d.getdata(get_subcatagory);
foreach (DataRow dr in dt.Rows)
{
ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr["Med_Sub"].ToString(),null, new EventHandler(ChildClick));
if (menuitem.DropDownItems.Contains(menuitem.DropDownItems[dr["Med_Sub"].ToString()]))
{
menuitem.DropDownItems.Remove(ssmenu);
}
else
{
menuitem.DropDownItems.Add(ssmenu);
}
}
}
thats he code i use for add submenu in menuitem
|
|
|
|
|
And what happens when you step through it in your debugger? Although, at a guess it is failing the if expression.
BTW please indent your code and put <pre> tags round it, so it looks like:
public void SubMenu(ToolStripMenuItem menuitem, string submenu)
{
string get_subcatagory = "select * from medicine_subcatagory where Cat_ID=(select Cat_ID from medicine_catagory where Med_Cat='" + allopathicToolStripMenuItem.Text + "')";
DataTable dt = d.getdata(get_subcatagory);
foreach (DataRow dr in dt.Rows)
{
ToolStripMenuItem ssmenu = new ToolStripMenuItem(dr["Med_Sub"].ToString(),null, new EventHandler(ChildClick));
if (menuitem.DropDownItems.Contains(menuitem.DropDownItems[dr["Med_Sub"].ToString()]))
{
menuitem.DropDownItems.Remove(ssmenu);
}
else
{
menuitem.DropDownItems.Add(ssmenu);
}
}
}
Use the best guess
|
|
|
|
|
yes it always goes into else code
|
|
|
|
|
Then you should be able to see how to fix it fairly easily.
Use the best guess
|
|
|
|
|
i dont know how to do it...
Can u help me in it...
just giv me a simple concept about how cud i check tht a particular menuitem, which is already get from database, exist over there and thn how to add new menuitem from database into that previously created menu.....
|
|
|
|
|
A quick glance at the documentation[^] suggests that you are testing against the wrong object type.
Use the best guess
|
|
|
|
|
thanks richard i solved my problem now
|
|
|
|
|
Dear All,
I am editing some lines in aP text file using c#, while editing the (') is replacing with another new charachter, i dont want this can any one help with code
StringBuilder newFile = new StringBuilder();
string temp = "";
string[] AllLines = File.ReadAllLines(FileName);
strStart = "<";
foreach (string strLine in AllLines)
{
if (strLine.Contains("CUsers") || strLine.Contains("_ags"))
{
fIndex = strLine.IndexOf(strStart);
sIndex = strLine.LastIndexOf("_ags");
temp = strLine.Remove(fIndex + 2, (sIndex - fIndex) + 2);
newFile.Append(temp + "\r\n");
continue;
}
newFile.Append(strLine + "\r\n");
}
File.WriteAllText(FileName, newFile.ToString());</pre>
Thanks in advance,
Srikanth
srikanth
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
static void Main(string[] args)
{
StringBuilder newFile = new StringBuilder();
string temp = "";
string[] AllLines = { "This <_ags> a' test?" };
string strStart = "<";
foreach (string strLine in AllLines)
{
if (strLine.Contains("CUsers") || strLine.Contains("_ags"))
{
int fIndex = strLine.IndexOf(strStart);
int sIndex = strLine.LastIndexOf("_ags");
temp = strLine.Remove(fIndex + 2, (sIndex - fIndex) + 2);
newFile.Append(temp + "\r\n");
continue;
}
newFile.Append(strLine + "\r\n");
}
Console.WriteLine(newFile.ToString());
Console.ReadKey();
}
} Can you change the "AllLines" variable to reflect your textfile contents, and show us an example of the output you'd expect on that? The code above would result in
This <_> a' test?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
for exmple in a file the text is like
We’re actually going to increase your savings to $40 cash back!
We’re '<$40 _agscash back!
after executind my code
out put is comming as
We?re actually going to increase your savings to $40 cash back!
We?re cash back!
in the above (') is replacing with (?) automatically
actually out put i need is
We’re actually going to increase your savings to $40 cash back!
We’re 'cash back!
|
|
|
|
|
srikanth kamuju wrote: n the above (') is replacing with (?) automatically I don't see any code that would do that. Sounds like a problem with the encoding; where are you viewing the string? Using notepad? Is it saved as UTF?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|